/**
 * @author Kristian Mandrup
 * @date June 10, 2009
 * @version 0.1
 * 
 * m3gen :: LogWrapper
 * 
 * Used to wrap function calls with begin/complete events for logging the generation proces
 */

 
m3gen.LogWrapper = function(context){
	this.context = context; 	
}

m3gen.LogWrapper.inherits(m3gen.Base);

/**
 * @param [Object} options
 * { method: function,  args: argObj, name: functionName}
 */ 
m3gen.LogWrapper.prototype.execute = function(options) {
	this.handleBegin(options.name, args);
	result = options.method(args);
	this.handleEnd(options.name, result);
	return result;
}

/**
 * Wrap with begin and end logging calls if logging is enabled
 * @param {Object} options
 */
m3gen.LogWrapper.log = function(options){
	if (options.context.getGlobalExecState().logging == true) {
		var LogWrapper = new m3gen.LogWrapper(options.context);
		return LogWrapper.execute({
			method: options.method,
			args: options.args,
			name: options.name
		});
	} else return options.method(options.args);
}
	